<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix"><span>用户信息</span></div>
    <div>
      <el-collapse v-model="activeNames">
        <el-collapse-item title="组件样式" name="1">
          <el-form size="medium" label-width="100px">
            <el-form-item label="头像形状">
              <el-radio-group v-model="data.avart_type">
                <el-radio :label="1">圆形</el-radio>
                <el-radio :label="2">圆角</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-form>
        </el-collapse-item>
        <el-collapse-item title="内容样式" name="2">
          <el-form size="medium" label-width="100px">
            <el-form-item label="背景">
              <el-radio-group v-model="data.bg_type">
                <el-radio :label="1">颜色</el-radio>
                <el-radio :label="2">背景图</el-radio>
              </el-radio-group>
              <div class="bg-color">
                <el-form size="medium" label-width="100px">
                  <el-form-item label="颜色" v-if="data.bg_type == 1"><ColorPicker :color="data" :name="'bg'"></ColorPicker></el-form-item>
                  <el-form-item label="背景图" v-if="data.bg_type == 2">
                    <div class="img_box"><Upload :tempUrl="data.imgbg" @input="getimg"></Upload></div>
                  </el-form-item>
                </el-form>
              </div>
            </el-form-item>
            <el-form-item label="昵称颜色"><ColorPicker :color="data" :name="'namecolor'"></ColorPicker></el-form-item>
            <el-form-item label="财务按钮">
              <el-checkbox-group v-model="data.finance.btns">
                <el-checkbox :label="0">余额</el-checkbox>
                <el-checkbox v-has="7" :label="1">积分</el-checkbox>
                <el-checkbox v-has="3" :label="2">优惠券</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="财务样式">
              <div class="bg-color">
                <el-form size="medium" label-width="100px">
                  <el-form-item label="数字颜色"><ColorPicker :color="data.finance" :name="'numcolor'"></ColorPicker></el-form-item>
                  <el-form-item label="标题颜色"><ColorPicker :color="data.finance" :name="'titlecolor'"></ColorPicker></el-form-item>
                </el-form>
              </div>
            </el-form-item>
            <el-form-item label="签到设置">
              <el-radio-group v-model="data.sign.show">
                <el-radio :label="1">开启</el-radio>
                <el-radio :label="0">关闭</el-radio>
              </el-radio-group>
              <div class="bg-color" v-if="data.sign.show">
                <el-form size="medium" label-width="100px">
                  <el-form-item label="背景颜色"><ColorPicker :color="data.sign" :name="'bg_color'"></ColorPicker></el-form-item>
                  <el-form-item label="文字颜色"><ColorPicker :color="data.sign" :name="'text_color'"></ColorPicker></el-form-item>
                  <el-form-item label="文字"><el-input style="width: 240px;" v-model="data.sign.text"></el-input></el-form-item>
                </el-form>
              </div>
            </el-form-item>
          </el-form>
        </el-collapse-item>
        <el-collapse-item title="导航内容" name="3">
          <el-form label-width="100px">
            <el-form-item label="是否开启">
              <el-radio-group v-model="data.btn.show">
                <el-radio :label="1">开启</el-radio>
                <el-radio :label="0">关闭</el-radio>
              </el-radio-group>
            </el-form-item>
            <template v-if="data.btn.show">
              <el-form-item label="文字颜色"><ColorPicker :color="data.btn" :name="'text_color'"></ColorPicker></el-form-item>
              <el-form-item label="图标颜色"><ColorPicker :color="data.btn" :name="'icon_color'"></ColorPicker></el-form-item>
            </template>
          </el-form>
          <draggable v-if="data.btn.show" element="div" style="padding: 10px;" v-model="data.list">
            <div class="container" v-for="(item, i) in data.list" :key="i">
              <i class="el-icon-error cancal" @click="dellist(i)"></i>
              <i class="el-icon-menu left"></i>
              <div class="content">
                <el-form size="medium" label-width="100px">
                  <el-form-item label="图标">
                    <div class="icon_box">
                      <span class="hasIcon" v-show="item.icon != ''">
                        <i :class="item.icon"></i>
                        <i class="icon-abl-close el-icon-error" @click="removeIcon(item)"></i>
                        <span class="choose_bar" @click="selecticon(item, i)"><i class="txt">替换</i></span>
                      </span>
                      <span class="noIcon" v-show="item.icon == ''"><i class="el-icon-plus" style="color:#409EFF;" @click="selecticon(item, i)"></i></span>
                    </div>
                  </el-form-item>
                  <el-form-item label="文字"><el-input type="text" placeholder="请输入内容" v-model="item.text" maxlength="5" show-word-limit></el-input></el-form-item>
                  <el-form-item label="链接地址">
                    <div @click="selectlink(item, i)"><Linkdiv :linkdata="item.linkdata"></Linkdiv></div>
                  </el-form-item>
                </el-form>
              </div>
            </div>
          </draggable>
          <el-button v-if="data.btn.show && data.list.length < 5" style="width: 100%" @click="addlist">添加</el-button>
        </el-collapse-item>
      </el-collapse>
    </div>
  </el-card>
</template>

<script>
import Upload from '@/components/Upload/SingleImage2';
import ColorPicker from '@/components/ColorPicker/index';
import draggable from 'vuedraggable';
import Linkdiv from '@/components/Link/index';

export default {
  props: {
    data: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      activeNames: ['1', '2', '3']
    };
  },
  components: {
    Upload,
    ColorPicker,
    draggable,
    Linkdiv
  },
  methods: {
    selectlink(item, i) {
      this.acivedata = item;
      this.activid = i;
      this.$parent.showlinkselcet(item);
    },
    getAData(item) {
      this.acivedata.linkdata = item;
    },
    getimg(img) {
      this.data.imgbg = img;
    },
    //删除图标
    removeIcon(tag) {
      this.data.content[tag] = '';
    },
    selecticon(item, i) {
      this.acivedata = item;
      this.activid = i;
      this.$parent.showiconselcet();
    },
    geticon(data) {
      this.acivedata.icon = data;
    },
    addlist() {
      this.data.list.push({
        icon: '',
        linkdata: {
          link: '',
          name: '',
          id: '',
          type: ''
        },
        text: ''
      });
    },
    dellist(i) {
      this.data.list.splice(i, 1);
    }
  }
};
</script>

<style scoped lang="scss">
.bg-color {
  border: 1px solid #e9edef;
  box-sizing: border-box;
  padding: 20px 0;
  border-radius: 2px;
  background: #f4f6f8;
}

.img_div {
  width: 40px;
  height: 40px;
}

.img_box {
  div {
    width: 40px;
    height: 40px;
  }
}
.icon_box {
  width: 36px;
  height: 36px;
  line-height: 36px;
  text-align: center;
  cursor: pointer;
  border: 1px solid #dcdfe6;
  position: relative;

  .icon-abl-close {
    position: absolute;
    top: -6px;
    right: -9px;
    color: rgba(0, 0, 0, 0.3);
    font-size: 16px;
  }

  &:hover {
    .choose_bar {
      display: block;
    }
  }

  .choose_bar {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    line-height: 18px;
    text-align: center;
    width: 100%;

    i.txt {
      display: inline-block;
      font-style: normal;
      -webkit-transform: scale(0.75);
      transform: scale(0.75);
      letter-spacing: 2px;
    }
  }
}
.container {
  display: flex;
  align-items: center;
  border: 1px solid #e9edef;
  background: #f4f6f8;
  padding: 10px;
  margin-bottom: 20px;
  position: relative;

  > i {
    font-size: 24px;
  }

  &:hover {
    .cancal {
      display: block;
    }
  }

  .cancal {
    font-size: 20px;
    position: absolute;
    right: -10px;
    top: -10px;
    cursor: pointer;
    display: none;
  }

  .content {
    flex: 1;
  }
}

.icon_box {
  width: 36px;
  height: 36px;
  line-height: 36px;
  text-align: center;
  cursor: pointer;
  border: 1px solid #dcdfe6;
  position: relative;

  .icon-abl-close {
    position: absolute;
    top: -6px;
    right: -9px;
    color: rgba(0, 0, 0, 0.3);
    font-size: 16px;
  }

  &:hover {
    .choose_bar {
      display: block;
    }
  }

  .choose_bar {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    line-height: 18px;
    text-align: center;
    width: 100%;

    i.txt {
      display: inline-block;
      font-style: normal;
      -webkit-transform: scale(0.75);
      transform: scale(0.75);
      letter-spacing: 2px;
    }
  }
}

.select_link {
  background: #fff;

  .select_btn {
    height: 36px;
    line-height: 28px;
    border-radius: 4px;
    padding: 4px 6px;
    cursor: pointer;
    color: #2d8cf0;
    box-sizing: border-box;
    border: 1px solid #dcdfe6;

    &:hover {
      border-color: #2d8cf0;
    }
  }
}
</style>
